package com.cn.coupon.service;

import com.cn.api.CouponFeignClient;
import com.cn.coupon.mapper.CouponMapper;
import com.cn.dto.CouponDTO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/coupon/api")
public class CouponService implements CouponFeignClient {
    @Resource
    private CouponMapper couponMapper;

    @PostMapping("/findAllCoupon")
    @Override
    public List<CouponDTO> findAllCoupon(CouponDTO couponDTO) {
        return couponMapper.findAllCoupon(couponDTO);
    }

    @PostMapping("/findById")
    @Override
    public CouponDTO findById(int id) {
        return couponMapper.findById(id);
    }

    @PostMapping("/findByStatus")
    @Override
    public CouponDTO findByStatus(int status) {
        return couponMapper.findByStatus(status);
    }

    @PostMapping("/createCoupon")
    @Override
    public int createCoupon(@RequestBody CouponDTO couponDTO) {
        return couponMapper.createCoupon(couponDTO);
    }

    @PostMapping("/editCoupon")
    @Override
    public Integer editCoupon(CouponDTO couponDTO) {
        return couponMapper.editCoupon(couponDTO);
    }

    @PostMapping("/deleteCoupon")
    @Override
    public Integer deleteCoupon(int id) {
        return couponMapper.deleteCoupon(id);
    }

    @PostMapping("/enable")//启用停用
    @Override
    public Integer enable( int id) {
        return couponMapper.enable(id);
    }

    @PostMapping("/findAllDetailed")
    @Override
    public List<CouponDTO> findAllDetailed(CouponDTO couponDTO) {
        return couponMapper.findAllDetailed(couponDTO);
    }

    @PostMapping("/findByNumber")
    @Override
    public CouponDTO findByNumber(String number) {
        return couponMapper.findByNumber(number);
    }

    @PostMapping("/findByState1")
    @Override
    public CouponDTO findByState(int state) {
        return couponMapper.findByState(state);
    }
}
